package com.blame.springblog.common.advice;

import com.blame.springblog.common.exception.BlogException;
import com.blame.springblog.pojo.response.Result;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.HandlerMethodValidationException;


@Slf4j
@RestControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler
    public Result exceptionHandler(Exception e){
//        log.error("Exception e:"+e);
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler
    public Result exceptionHandler(BlogException e){
//        log.error("Exception e:"+e);
        return Result.fail(e.getErrMsg());
    }

    @ExceptionHandler
    public Result exceptionHandler(HandlerMethodValidationException e){
        return Result.fail(e.getMessage());
    }
}
